const vm = new Vue({
    el: '#app',
    data: {
        tableData: [],//表格当前页数据
        pagesize: 20,//默认每页数据量
        curRowData: {}, //当前选择行数据
        currentPage: 1,//当前页码
        start: 1, //查询的页码
        totalCount: '',//默认数据总数
        multipleSelection: [],//多选数组
        dialogFormVisible:false,//编辑框
        q:{//搜索条件
            teamName:'',
            mobile:'',
            sourceType:'',
            auditStatus:''
        },
        idCardImgs:[],//身份证正反面url
    },
    created () {
        Vue.nextTick(()=>{
            //载入数据
            vm.loadData(vm.currentPage, vm.pagesize);
        });
    },
    methods: {
        //从后台获取数据
        loadData: function (page, limit) {
            // let {teamName,mobile,sourceType,auditStatus} = vm.q
            // const params = {page,limit,teamName,mobile,sourceType,auditStatus}
            vm.q.page=vm.currentPage
            vm.q.limit=vm.pagesize
            $.ajax({
                type: "POST",
                url: baseURL + "userTeam/userteam/list",
                contentType: "application/json",
                data: JSON.stringify(vm.q),
                success: function(r){
                    if(r.code === 0){
                        vm.tableData = r.page.list
                        vm.totalCount = r.page.totalCount
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        //多选响应
        handleSelectionChange: function(val) {
            vm.multipleSelection = val;
        },
        //点击行响应
        handleclick: function(row, event, column){
            vm.curRowData = JSON.parse(JSON.stringify(row));//深克隆
        },
        //弹出编辑框
        handleEdit: function(index, row) {
            vm.curRowData = JSON.parse(JSON.stringify(row));//深克隆
            vm.dialogFormVisible = true
        },
        //提交编辑
        edit() {
            $.ajax({
                type: "POST",
                url: baseURL + "userTeam/userteam/update",
                contentType: "application/json",
                data: JSON.stringify(vm.curRowData),
                success: function(r){
                    if(r.code === 0){
                        vm.loadData(vm.currentPage, vm.pagesize);//刷新后页面在当前页
                        //vm.loadData(vm.currentPage=1, vm.pagesize);刷新后页面回到首页
                        vm.dialogFormVisible = false
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        //弹出审核框
        handleAudit: function(index, row) {
            vm.curRowData = JSON.parse(JSON.stringify(row));//深克隆
            if (vm.curRowData.idCardUrls) {
              vm.idCardImgs=vm.curRowData.idCardUrls.split(',')
            }
            vm.dialogFormVisible = true;
            Vue.nextTick(function () {
                // 图片预览初始化
                $('#view').viewer();
                /* oss上传 */
                $.files_up_oss({
                    id: ["uploadImage1"],//按钮id
                    url: "/sys/oss/getSignature",
                    dir: "config/couponucenter/",
                    file_type: "jpg,png,gif,psd,ai,cdr,eps,ppt,word,excel,pdf,tiff,rar,zip,7z,gif,AVI,WMV,RM,RMVB,MPEG1,MPEG2,MPEG4,3GP,ASF,SWF,VOB,DAT,MOV,M4V,FLV,F4V,MKV,TIF",
                    size: "100mb",//mb
                    view_url: window.parent.vm.ossHost
                }, function (index_number, json) {
                    if (json.Status == 'OK') {
                        Vue.set(vm.curRowData, 'businessUrl', json.filename);
                    }
                })
            });
        },
        //审核通过
        audit() {
            $.ajax({
                type: "POST",
                url: baseURL + "userTeam/userteam/audit",
                contentType: "application/json",
                data: JSON.stringify(vm.curRowData),
                success: function(r){
                    if(r.code === 0){
                        alert('审核通过')
                        vm.dialogFormVisible = false
                        vm.loadData(vm.currentPage=1, vm.pagesize);//刷新后页面回到首页
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        //审核拒绝
        pass() {
            $.ajax({
                type: "POST",
                url: baseURL + "userTeam/userteam/pass",
                contentType: "application/json",
                data: JSON.stringify(vm.curRowData),
                success: function(r){
                    if(r.code === 0){
                        alert('拒绝成功')
                        vm.dialogFormVisible = false
                        vm.loadData(vm.currentPage=1, vm.pagesize);//刷新后页面回到首页
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },

        //单行删除
        handleDelete: function(index, row) {
            $.ajax({
                type: "POST",
                url: baseURL + "userTeam/userteam/delete",
                contentType: "application/json",
                data: JSON.stringify(row),
                success: function(r){
                    if(r.code === 0){
                        alert('删除成功')
                        vm.loadData(vm.currentPage, vm.pagesize);//刷新后页面在当前页
                        //vm.loadData(vm.currentPage=1, vm.pagesize);刷新后页面回到首页
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        //搜索
        search: function(){
            vm.loadData(vm.start, vm.pagesize);
        },
        //重置
        rest() {
            vm.q.teamName=''
            vm.q.mobile=''
            vm.q.sourceType=''
            vm.q.auditStatus=''
            vm.loadData(vm.currentPage, vm.pagesize);
        },
        add() {

        },
        //每页显示数据量变更
        handleSizeChange: function(val) {
            vm.pagesize = val;
            vm.loadData(vm.currentPage, vm.pagesize);
        },
        //页码变更
        handleCurrentChange: function(val) {
            vm.currentPage = val;
            vm.loadData(vm.currentPage, vm.pagesize);
        },
        //together：一企推，agent：代理点二级分销，wechat：微信朋友圈推广, second:二级分销(不审)
        sourceTypeFormatter(val) {
            if(val.sourceType == 'together')
            {return "一企推"}
            else if (val.sourceType == 'agent')
            {return "代理点二级分销"}
            else if (val.sourceType == 'wechat')
            {return "微信朋友圈推广"}
            else if (val.sourceType == 'second')
            {return "二级分销(不审)"}
            else
            {return ""}
        },
        //审核状态 0:待审核 1:审核通过 2:已拒绝
        auditStatusFormatter(val) {
            if(val.auditStatus == 0)
            {return "待审核"}
            else if (val.auditStatus == 1)
            {return "审核通过"}
            else if (val.auditStatus == 2)
            {return "已拒绝"}
            else
            {return ""}
        },
    }
});
